-
Notifications
You must be signed in to change notification settings - Fork 13.6k
clarify wording of match ergonomics diagnostics (rust_2024_incompatible_pat
lint and error)
#144006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
b968622
to
6751630
Compare
Some changes occurred in match checking cc @Nadrieril |
6751630
to
981b966
Compare
mir_build_rust_2024_incompatible_pat = {$bad_modifiers -> | ||
mir_build_rust_2024_incompatible_pat = explicit {$bad_modifiers -> | ||
*[true] binding modifiers{$bad_ref_pats -> | ||
*[true] {" "}and reference patterns | ||
[false] {""} | ||
} | ||
[false] reference patterns | ||
} may only be written when the default binding mode is `move`{$is_hard_error -> | ||
} may not be written within elided reference patterns{$is_hard_error -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "explicit binding modifiers may not be mixed with automatic reference elision"? Not great either, we might need an official term for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tricky! I'm avoiding "mixed with" since it's only an error when they're nested; that wording would maybe suggest they can't be used in the same pattern at all. An official term could help, but if it doesn't stand on its own we're still relying on users to read and understand the Edition Guide or Reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though my wording will also not be entirely right either for new match ergonomics, since it would be possible to match on inherited references and reset the default binding mode. I'm not really sure how to capture the nuance there in a succinct and self-contained manner. Maybe it needs more subdiagnostic notes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe we can keep "elided reference pattern" if there's a label that points to "a reference was elided here" or sth...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't read that's literally already there x) ok, then we should use the same terminology in both messages:
error: explicit binding modifiers may not be written within elided reference patterns
...
note: matching on a reference type with a non-reference pattern elides the reference
so that users understand the causality between these things. Problem is that this doesn't explain what "eliding a reference" does...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we go all-in with the new mental model, this might look like:
error: cannot borrow twice in a pattern
...
note: matching on a reference type with a non-reference pattern makes variables within borrow their targets already
or
error: cannot dereference an implicit borrow
...
note: matching on a reference type with a non-reference pattern causes the contents to be implicitly borrowed
Partially addresses #143557:
&
written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about&
patterns without further explanation.This only changes the diagnostic messages, not the code suggestion or the Edition Guide.
r? @Nadrieril or reassign